<?php

namespace App\Http\Controllers\Home;

use App\Models\User;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class RegisterController extends Controller
{
    //注册界面
    public function index()
    {
        return view('register.index');

    }
    //注册行为
    public function register()
    {
        //验证
        $this->validate(request(),[
            'username'=>'required|string|min:5|max:12|unique:users,username',
            'email'=>'required|email|unique:users,email',
            'password'=>'required|min:6|string|confirmed'
        ]);
        //逻辑
        $username=request('username');
        $email=request('email');
        $password=bcrypt(request('password'));
        $ip=request()->getClientIp();
        User::create(compact('username','email','ip','password'));
        //渲染
        return redirect('/login');

    }
}
